package com.lanhe.game.terraceEarn;

import cn.hutool.core.util.ObjectUtil;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.utils.StringUtils;
import com.lanhe.game.sysAppUser.service.ISysAppUserService;
import com.lanhe.game.terraceEarn.domain.LanheTerraceEarn;
import com.lanhe.game.terraceEarn.service.ILanheTerraceEarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/terraceEarn")
public class ApiTerraceEarnController extends BaseController {

    @Autowired
    private ILanheTerraceEarnService lanheTerraceEarnService;
    @Autowired
    private ISysAppUserService sysAppUserService;

    /**
     * 添加每个用户在不同平不同广告的收益
     * @param lanheTerraceEarn
     * @return
     */
    @PostMapping("/adEarnings")
    public AjaxResult getAdEarnings(@Validated @RequestBody LanheTerraceEarn lanheTerraceEarn){
        if (StringUtils.isEmpty(lanheTerraceEarn.getAdType())){
            return error("广告类型不能为空");
        }
        if (StringUtils.isEmpty(lanheTerraceEarn.getPackageName())){
            return error("包名不能为空");
        }
        if (StringUtils.isEmpty(lanheTerraceEarn.getMediaId())){
            return error("媒体id不能为空");
        }
        if (StringUtils.isEmpty(lanheTerraceEarn.getPostId())){
            return error("广告位id不能为空");
        }
         if (ObjectUtil.isNull(lanheTerraceEarn.getAppUserId())){
             return error("用户不能为空");
        }
        return success(lanheTerraceEarnService.insertTerraceEarn(lanheTerraceEarn));
    }

    /**
     *  获取用户的信息
     * @param appUserId
     * @return
     */
    @GetMapping("/appUserDetails/{appUserId}")
    public AjaxResult getAppUserDetails(@PathVariable("appUserId") Long appUserId){
        System.err.println("appUserId "+appUserId);
        // 获取用户信息
        return success(sysAppUserService.getById(appUserId));
    }
}
